﻿#include "formprinterpack.h"
#include "excel.hpp"
#include "qdebug.h"
#include "ui_formprinterpack.h"
#include <formprinter.h>
#include <ui_formprinter.h>
#include <QMessageBox>
#include <Windows.h>
#include <myprocess.h>
#include <QFile>
#include <MainWindow.h>
#include <QMenu>
#include <workorder.h>
#include <QDesktopServices>

FormPrinterPack::FormPrinterPack(FormPrinter *parent)
    : ui(new Ui::FormPrinterPack)
{
    ui->setupUi(this);
    formPrinter = parent;
    // // //表格
    standItemModel = new QStandardItemModel();
    ui->tableView->setModel(standItemModel);                                            //挂载表格模型
    // 设置表格属性
    ui->tableView->horizontalHeader()->setDefaultAlignment(Qt::AlignLeft);              //表头信息显示居中
    ui->tableView->setEditTriggers(QAbstractItemView::SelectedClicked);                 //设置表格属性(如只读，不能编辑)
    ui->tableView->setSelectionBehavior(QTableView::SelectRows);                        //整行选中
    ui->tableView->resizeColumnToContents(0);
    QPalette p = ui->tableView->palette();
    p.setColor(QPalette::Inactive, QPalette::Highlight, p.color(QPalette::Active, QPalette::Highlight));
    p.setColor(QPalette::Inactive, QPalette::HighlightedText, p.color(QPalette::Active, QPalette::HighlightedText));
    ui->tableView->setPalette(p);
    ui->tableView->setContextMenuPolicy(Qt::CustomContextMenu);
    delegate = new MyRowDelegate(); // 委托
    ui->tableView->setItemDelegate(delegate);
    connect(ui->tableView, &QTableView::customContextMenuRequested
            , this, &FormPrinterPack::on_tableViewCustomContextMenuRequested);
    // 暂时禁用不需要特定的控件
    ui->label_8->hide();
    ui->spinBox_4->hide();
}

FormPrinterPack::~FormPrinterPack()
{
    delete ui;
}

// 切换工单
void FormPrinterPack::on_combobox_change(QString str)
{
    if(str.isEmpty()){
        QMessageBox::warning(this,"错误","未打开工单号,请在<铭牌和条码>中选择工单号.");
        return;
    }
    if(combo_sub!=str){
        standItemModel->clear();
        combo_sub=str;
        delegate->clearGreenRows();
    }
    ui->groupBox->setTitle("{"+formPrinter->ui->comboBox->currentText()+"}");
    // 获取工单号配置
    QString strTmp=formPrinter->workOrder->getInfor("a_box_num");
    ui->spinBox_2->setValue(strTmp.isEmpty()?50:strTmp.toInt());
    strTmp=formPrinter->workOrder->getInfor("a_box_details");
    ui->checkBox_3->setChecked(strTmp.isEmpty()?0:strTmp.toInt());
    strTmp=formPrinter->workOrder->getInfor("multiple_rows_and_columns");
    ui->checkBox_4->setChecked(strTmp.toInt());
    if(strTmp.isEmpty()){
        ui->spinBox_3->setEnabled(0);
        ui->spinBox_3->setValue(1);
    }else{
        ui->spinBox_3->setEnabled(1);
        ui->spinBox_3->setValue(strTmp.toInt());
    }
}

// 生成箱号数据列表
void FormPrinterPack::on_pushButton_2_clicked()
{
    standItemModel->clear();
    delegate->clearGreenRows();
    QSet<int> printed_rows = formPrinter->workOrder->getLog("log2.dat");
    delegate->addGreenRows(printed_rows);
    int a_box_num=ui->spinBox_2->value();       // 一箱的数量
//    int page_box_num=ui->spinBox_3->value();    // 一箱要打多少张贴纸，分组用
//    int start_order_num=ui->spinBox_4->value(); // 起始序号
    QVector<QStringList> all_data;
    formPrinter->getTableView()->getDatas(all_data, 0, 1, 1);
    if(all_data.empty()) return;
    if(all_data[0].empty()) return;
    // 计算总箱数
    int totalNum = all_data.size()/a_box_num+(all_data.size()%a_box_num==0?0:1);
    if(totalNum==0||totalNum>10000){QMessageBox::warning(this, "错误", "已严格控制总箱数[1-10000],当前计算:"+QString::number(totalNum)); return;}
    // 添加字段：箱号，总箱数，数量，SN起始，SN结束，明细数据，SN01-SN{数量}，（如果TUSN存在，则加：TUSN起始，TUSN结束，TUSN明细数据，TUSN01-TUSN{数量}）
    QStringList str;
    str << "总箱数" << "箱号" << "数量" << "SN起始" << "SN结束" << "SN明细";;
    for (int i = 0; i < a_box_num; ++i) {
        str << "SN"+QString("%1").arg(i+1, ui->spinBox_2->text().size(), 10, QLatin1Char('0'));
    }
    bool isTUSN=!all_data[0][1].isEmpty();
    if(isTUSN){
        str << "TUSN起始" << "TUSN结束" << "TUSN明细";
        for (int i = 0; i < a_box_num; ++i) {
            str << "TUSN"+QString("%1").arg(i+1, ui->spinBox_2->text().size(), 10, QLatin1Char('0'));
        }
    }
    standItemModel->setHorizontalHeaderLabels(str);
    // 持续计算和添加数据
    for (int i = 0; i < totalNum; ++i) {
        standItemModel->setItem(i, 0, new QStandardItem(QString::number(totalNum)));
        standItemModel->setItem(i, 1, new QStandardItem(QString::number(i+1)));
        standItemModel->setItem(i, 2, new QStandardItem(QString::number(a_box_num)));
        QString a_box_data, a_box_data2;
        for (int sn_i = 0; sn_i < a_box_num; ++sn_i) {
            int order=i*a_box_num+sn_i;
            if(sn_i==0){    // sn起始
                standItemModel->setItem(i, 3, new QStandardItem(all_data[order][0]));
                if(isTUSN){
                    standItemModel->setItem(i, 4+a_box_num+2, new QStandardItem(all_data[order][1]));
                }
            }
            standItemModel->setItem(i, 6+sn_i, new QStandardItem(all_data[order][0]));
            a_box_data+=all_data[order][0]+delimiter;
            if(isTUSN){
                standItemModel->setItem(i, 6+sn_i+a_box_num+3, new QStandardItem(all_data[order][1]));
                a_box_data2+=all_data[order][1]+delimiter;
            }
            // sn结束
            if(order+1==all_data.size()){   // 最后一箱有余
                standItemModel->setItem(i, 4, new QStandardItem(all_data[order][0]));
                standItemModel->setItem(i, 2, new QStandardItem(QString::number(sn_i+1)));
                if(isTUSN){
                    standItemModel->setItem(i, 4+a_box_num+3, new QStandardItem(all_data[order][1]));
                }
                break;
            }
            else if(sn_i==a_box_num-1){
                standItemModel->setItem(i, 4, new QStandardItem(all_data[order][0]));
                if(isTUSN){
                    standItemModel->setItem(i, 4+a_box_num+3, new QStandardItem(all_data[order][1]));
                }
            }
        }
        // 生成一箱的详细数据
        if(ui->checkBox_3->isChecked()){
            standItemModel->setItem(i, 5, new QStandardItem(a_box_data));
            if(isTUSN)
                standItemModel->setItem(i, 5+a_box_num+3, new QStandardItem(a_box_data2));
        }
    }
    // 如果btw使用的数据库文件不存在，则生成此文件和放置默认数据
    if(standItemModel->rowCount()>0){
        ui->tableView->selectionModel()->select(standItemModel->index(0,0), QItemSelectionModel::ClearAndSelect);
        ExportData();
        ui->tableView->selectionModel()->select(standItemModel->index(0,0), QItemSelectionModel::Deselect);
    }
}

// 导出
int FormPrinterPack::ExportData(bool isSaveLog){
    QVector<QStringList> v_data;
    QString str_log;
    bool have_green=false;
    QSet<int> green_set_tmp;
    // 先保存字段
    QStringList d_tmp;
    if(!ui->checkBox_4->isChecked()){ // 方式一，一箱单张设计
        for(int i=0;i<standItemModel->columnCount();i++){
            d_tmp.push_back(standItemModel->headerData(i, Qt::Horizontal).toString());
        }
        for (int r=0; r<standItemModel->rowCount(); r++) {
            bool isSelect=ui->tableView->selectionModel()->isSelected(standItemModel->index(r,0));
            if(!isSelect||ui->tableView->isRowHidden(r)) continue;
            QStringList v_str;
            if(!have_green){
                if(delegate->isRowGreen(r)) have_green=true;
            }
            for (int c=0; c<standItemModel->columnCount(); c++) {
                QVariant data = standItemModel->data(standItemModel->index(r, c), Qt::DisplayRole);
                if(data.isValid()){
                    v_str.push_back(data.toString());
                    if(isSaveLog) green_set_tmp.insert(r);
                }else{
                    v_str.push_back("");
                }
            }
            if(!v_str.empty())
                v_data.push_back(v_str);
        }
        if(ui->checkBox->isChecked()) std::reverse(v_data.begin(), v_data.end());
    }
    else{ // 方式二，多行多列设计
        int a_box_num=ui->spinBox_2->value();       // 一箱的数量
        int page_box_num=ui->spinBox_3->value();    // 一箱要打多少张贴纸，分组用
        int a_page_num=a_box_num/page_box_num;      // 一张贴纸的sn数量
        if(a_box_num%page_box_num!=0){
            if(QMessageBox::No==QMessageBox::warning(this, "警告", "{一箱的数量}除以{一箱要打的纸张数}不等于整数，是否继续？", QMessageBox::Yes|QMessageBox::No))
                return 0;
        }
        int columnNum=0;
        // ////字段
        bool isTusn=-1!=standItemModel->headerData(standItemModel->columnCount()-1, Qt::Horizontal).toString().indexOf("TUSN");
        // SN(SN,TUSN,总箱数，箱号，数量，SN起始，SN结束，SN明细)
        d_tmp.push_back("SN");
        if(isTusn){
            d_tmp.push_back("TUSN");
        }
        for(;columnNum<standItemModel->columnCount();columnNum++){
            // 跳过sn和tusn字段
            if((6<=columnNum&&columnNum<6+a_box_num)||
                (isTusn&&6+3+a_box_num<=columnNum&&columnNum<6+3+a_box_num+a_box_num)
                ){
                continue;
            }
            d_tmp.push_back(standItemModel->headerData(columnNum, Qt::Horizontal).toString());
        }
        // ////数据
        for (int r=0; r<standItemModel->rowCount(); r++) {
            columnNum=0;
            bool isSelect=ui->tableView->selectionModel()->isSelected(standItemModel->index(r,0));
            if(!isSelect||ui->tableView->isRowHidden(r)) continue;
            QStringList list1,list2;        //非SN非TUSN数据
            QStringList snList, tusnList;   //SN和TUSN数据
            if(!have_green){
                if(delegate->isRowGreen(r)) have_green=true;
            }
            for (; columnNum<standItemModel->columnCount(); columnNum++) {
                QVariant dataTmp = standItemModel->data(standItemModel->index(r, columnNum), Qt::DisplayRole);
                QString data=dataTmp.isValid()?dataTmp.toString():"";
                if(columnNum<6){
                    list1.push_back(data);
                }
                else if(6<=columnNum&&columnNum<6+a_box_num){
                    snList.push_back(data);
                }else if(isTusn&&6+3+a_box_num<=columnNum&&columnNum<6+3+a_box_num+a_box_num){
                    tusnList.push_back(data);
                }else if(isTusn){
                    list2.push_back(data);
                }else continue;
                if(isSaveLog) green_set_tmp.insert(r);
            }
            // (SN,{TUSN},总箱数，箱号，数量，SN起始，SN结束，SN明细,{TUSN起始，TUSN结束，TUSN明细})
            QStringList v_str;
            if(isTusn&&snList.size()!=tusnList.size()){
                //qDebug() << "snList.size()!=tusnList.size()";
                return 0;
            }
            if(ui->checkBox->isChecked()){
                std::reverse(snList.begin(), snList.end());
                std::reverse(tusnList.begin(), tusnList.end());
            }
            // 获取分组数据,存明细到data_group, data_group2中
            QString dataTmp, dataTmp2;
            QStringList data_group, data_group2;
            for (int i = 0; i < snList.size(); ++i) {
                dataTmp+=snList[i]+delimiter;
                if((i+1)%a_page_num==0||(i==snList.size()-1)){
                    data_group.push_back(dataTmp);
                    dataTmp="";
                }
                if(isTusn){
                    dataTmp2+=tusnList[i]+delimiter;
                    if((i+1)%a_page_num==0||(i==snList.size()-1)){
                        data_group2.push_back(dataTmp2);
                        dataTmp2="";
                    }
                }
            }
            // // //存数据②（sn明细不分割分组）
            for (int i = 0; i < snList.size(); ++i) {
                if(!isTusn){
                    if((i+1)%a_page_num==1){
                        v_str=QStringList({snList[i],list1[0],list1[1],list1[2],list1[3],list1[4],list1[5]});
                    }
                    else
                        v_str=QStringList({snList[i],list1[0],list1[1],list1[2],list1[3],list1[4],""});
                }
                else{
                    if((i+1)%a_page_num==1){
                        v_str=QStringList({snList[i],tusnList[i],list1[0],list1[1],list1[2],list1[3],list1[4],list1[5],list2[0],list2[1],list2[2]});
                    }
                    else
                        v_str=QStringList({snList[i],tusnList[i],list1[0],list1[1],list1[2],list1[3],list1[4],"",list2[0],list2[1],""});
                }
                if(!v_str.empty())
                    v_data.push_back(v_str);
            }
            // // //存数据①（sn明细也分割分组）
            // for (int i = 0; i < snList.size(); ++i) {
            //     if(!isTusn){
            //         if((i+1)%a_page_num==1){
            //             v_str=QStringList({snList[i],list1[0],list1[1],list1[2],list1[3],list1[4],data_group[0]});
            //             data_group.removeFirst();
            //         }
            //         else
            //             v_str=QStringList({snList[i],list1[0],list1[1],list1[2],list1[3],list1[4],""});
            //     }
            //     else{
            //         if((i+1)%a_page_num==1){
            //             v_str=QStringList({snList[i],tusnList[i],list1[0],list1[1],list1[2],list1[3],list1[4],data_group[0],list2[0],list2[1],data_group2[0]});
            //             data_group.removeFirst();
            //             data_group2.removeFirst();
            //         }
            //         else
            //             v_str=QStringList({snList[i],tusnList[i],list1[0],list1[1],list1[2],list1[3],list1[4],"",list2[0],list2[1],""});
            //     }
            //     if(!v_str.empty())
            //         v_data.push_back(v_str);
            // }
        }
    }
    if(v_data.empty()) {
        QMessageBox::warning(this, "错误", "未选中任意行!");
        return 0;
    }
    if(isSaveLog){
        if(have_green){
            if(QMessageBox::No==QMessageBox::question(this, "警告", "选中行中存在已打印的数据，是否继续？", QMessageBox::Yes|QMessageBox::No, QMessageBox::No))
                return 0;
        }
        delegate->addGreenRows(green_set_tmp); // 已打印，赋绿色
    }
    v_data.push_front(d_tmp);
    str_log=data2QString(v_data);
    if(0==formPrinter->getDataMethod()){
        saveXLS("./btw/"+formPrinter->ui->comboBox->currentText()+"/2.xls", v_data);
        QFile::remove("./btw/"+formPrinter->ui->comboBox->currentText()+"/2.txt");
    }
    else{
        saveCSV("./btw/"+formPrinter->ui->comboBox->currentText()+"/2.txt", v_data);
        QFile::remove("./btw/"+formPrinter->ui->comboBox->currentText()+"/2.xls");
    }
    if(isSaveLog){
        MainWindow::log(formPrinter->ui->comboBox->currentText()+":"+str_log);
        formPrinter->workOrder->log("log2.dat", delegate->getGreenRows());    // 保存打印记录,标记颜色用
    }
    return v_data.size();
}

// 打印
void FormPrinterPack::on_pushButton_clicked()
{
    HWND hWnd=formPrinter->myPrinterFun.bartendGetMainWin();
    if(formPrinter->getPrintMethod()==0){
        if(!QFile::exists(formPrinter->bartend_exe)){
            QMessageBox::warning(this, "错误", "未找到打印程序(bartender),请在\"菜单\"中设置.");
            return;
        }
        // 有bartender后台,关闭后才能继续
        if(hWnd){
            QMessageBox::warning(this, "错误", "打印程序(Bartender)在前台,请关闭后才能继续.");
            ShowWindow(hWnd, SW_RESTORE);
            SetForegroundWindow(hWnd);
            return;
        }
    }else{
        if(!QFile::exists(formPrinter->bylabel_exe)){
            QMessageBox::warning(this, "错误", "未找到打印程序(bartender),请在\"菜单\"中设置.");
            return;
        }
    }
    if(QProcess::Running==formPrinter->runexe->state()){
        if(IsWindowVisible(formPrinter->myPrinterFun.bylGetMainWin(formPrinter->ui->comboBox->currentText()+"/2"))||QMessageBox::Yes==QMessageBox::warning(this, "错误", "后台程序正在运行,是否强制结束并打印?", QMessageBox::Yes|QMessageBox::No)){
            formPrinter->runexe->kill();
            formPrinter->runexe->waitForFinished(100);
        }else{
            return;
        }
    }
    int printNum=ExportData(1);
    if(printNum<2) return;
    if(0==formPrinter->getPrintMethod()){    // 调用bartender进行打印
        QStringList arguments;
        arguments << "/F="+QDir::toNativeSeparators("./btw/"+formPrinter->ui->comboBox->currentText()+"/2.btw") << (ui->checkBox_2->isChecked()?"/FPD":"/P") << "/X";
        formPrinter->runexe->start(formPrinter->bartend_exe, arguments);
        MainWindow::static_text(QString("外箱(bartender)打印调用成功,总数:%1").arg(printNum-1));
        formPrinter->runexe->ExitMsg("调用bartender打印铭牌条码打印调用结束1!", "调用bartender打印铭牌条码打印调用结束2!");
    }else{                                  // //调用bylabel进行打印
        // 打开bylabel贴纸
        HWND beforHwnd=GetForegroundWindow();
        on_pushButton_3_clicked();
        // 循环判断是否已经打开bylabel贴纸
        QTimer *timer = new QTimer(this);
        timer->setInterval(100);
        connect(timer, &QTimer::timeout, this, [=](){
            HWND hWnd=formPrinter->myPrinterFun.bylGetMainWin(formPrinter->ui->comboBox->currentText()+"/2");
            if(NULL!=hWnd){
                Sleep(1000);
                // MoveWindow(hWnd, 0, 0, 100, 100, 0); // 会导致bylabel打印的条码上下偏位问题
                ShowWindow(hWnd, SW_HIDE);
                timer->stop();
                Sleep(1000);
                MyPrinterFun myPrinterFun;
                HWND main_print_win = myPrinterFun.bylGetPrinterWindow();
                if(NULL==main_print_win){
                    // 发送键值Ctrl+P
                    SetForegroundWindow(hWnd);
                    keybd_event(VK_CONTROL, 0, 0, 0);
                    Sleep(10);
                    keybd_event('P', 0, 0, 0);
                    Sleep(10);
                    keybd_event('P', 0, KEYEVENTF_KEYUP, 0);
                    keybd_event(VK_CONTROL, 0, KEYEVENTF_KEYUP, 0);
                    Sleep(500);
                    main_print_win = myPrinterFun.bylGetPrinterWindow();
                }
                QList<HWND> list_hwnd=myPrinterFun.bylGetPrinterWindowNum(main_print_win);
                //设置参数起始标签，打印标签数量，相同标签打印数量
                if(list_hwnd.size()==3){
                    SendMessageW(list_hwnd[0], WM_SETTEXT, 0, (LPARAM)L"1"); //起始标签
                    SendMessageW(list_hwnd[1], WM_SETTEXT, 0, (LPARAM)QString::number(printNum-1).toStdWString().c_str()); //打印标签数量
                    SendMessageW(list_hwnd[2], WM_SETTEXT, 0, (LPARAM)L"1"); //相同标签打印数量
                    // 调用打印按钮
                    Sleep(10);
                    HWND hwnd_OK = myPrinterFun.bylGetPrinterWindowOK(main_print_win);
                    SendMessage(hwnd_OK, BM_CLICK, 0, 0);
                    MainWindow::static_text(QString("外箱(byl)打印调用成功,总数:%1").arg(printNum-1));
                }else{
                    MainWindow::static_text(QString("外箱(byl)打印调用失败(未找到:起始标签，打印标签数量，相同标签打印数量)!"));
                }
                SetForegroundWindow(beforHwnd);
                timer->deleteLater();
            }
        });
        timer->start();
    }
    ui->tableView->setFocus();
}

// 滚动到指定行
void FormPrinterPack::on_spinBox_valueChanged(int arg1)
{
    arg1--;
    ui->tableView->scrollTo(standItemModel->index(arg1, 0));
    bool isSelect=ui->tableView->selectionModel()->isSelected(standItemModel->index(arg1, 0));
    for (int row=0; row < standItemModel->rowCount(); row++){
        ui->tableView->selectionModel()->select(standItemModel->index(arg1,row), isSelect?QItemSelectionModel::Deselect:QItemSelectionModel::Select);
    }
    QTimer::singleShot(400, this, [=](){
        for (int row=0; row < standItemModel->rowCount(); row++){
            ui->tableView->selectionModel()->select(standItemModel->index(arg1,row), isSelect?QItemSelectionModel::Select:QItemSelectionModel::Deselect);
        }
    });
}

// 列表右键
void FormPrinterPack::on_tableViewCustomContextMenuRequested(const QPoint &pos)
{
    Q_UNUSED(pos);
    QMenu menu;
    //添加右键菜单的选项
    menu.addAction("导出选中");
    menu.addAction("跳转到未打印行");
    connect(&menu, &QMenu::triggered, [=](QAction *action){
        if("导出选中"==action->text()){
            if(ExportData(0)>1) QMessageBox::information(this, "导出成功", "已导出数据至2.xls/2.txt,请编辑2.btw/2.byl打印文件,链接此数据库即可.");
        }else if("跳转到未打印行"==action->text()){
            int rowTmp=-1;
            for (int r=0; r<standItemModel->rowCount(); r++) {
                if(!ui->tableView->isRowHidden(r)&&!delegate->isRowGreen(r)){
                    rowTmp=r;
                    break;
                }
            }
            if(rowTmp!=-1){
                on_spinBox_valueChanged(rowTmp+1);
            }
        }
    });
    // 显示menu菜单并设置其显示位置为鼠标位置
    menu.exec(QCursor::pos());
}

void FormPrinterPack::on_spinBox_2_textChanged(const QString &arg1)
{
    formPrinter->workOrder->setInfor("a_box_num", arg1);
}

void FormPrinterPack::on_checkBox_3_clicked(bool checked)
{
    formPrinter->workOrder->setInfor("a_box_details", QString::number(checked));
}

void FormPrinterPack::keyPressEvent(QKeyEvent *event){
    // 按下了Ctrl+P
    if (event->modifiers() == Qt::ControlModifier && event->key() == Qt::Key_P) {
        on_pushButton_clicked();
        event->accept();
    } else {
        QWidget::keyPressEvent(event);
    }
}

// 打开btw
void FormPrinterPack::on_pushButton_3_clicked()
{
    if(0==formPrinter->getPrintMethod()){
        // 有bartender后台,关闭后才能继续
        HWND hWnd=FindWindowW(L"BartendWindowClass", NULL);
        wchar_t windowTitle[256] = {0};
        int length = GetWindowTextW(hWnd, windowTitle, sizeof(windowTitle) / sizeof(windowTitle[0]));
        if(length>0&&-1!=QString::fromStdWString(windowTitle).indexOf(".btw")){
            QMessageBox::warning(this, "错误", "打印程序(bartender)在前台, 请关闭后才能继续.");
            ShowWindow(hWnd, SW_RESTORE);
            SetForegroundWindow(hWnd);
            return;
        }
        QStringList arguments;
        arguments << "/F="+QDir::toNativeSeparators(QDir("./btw/"+formPrinter->ui->comboBox->currentText()).absolutePath()+"/2.btw");
        formPrinter->runexe->start(formPrinter->bartend_exe, arguments);
    }else{
        QStringList arguments;
        arguments << QDir("./btw/"+formPrinter->ui->comboBox->currentText()).absolutePath()+"/2.byl";
        formPrinter->runexe->start(formPrinter->bylabel_exe, arguments);
    }
}

// 打开路径
void FormPrinterPack::on_pushButton_4_clicked()
{
    QDesktopServices::openUrl(QUrl("file:///"+QDir("./btw/"+formPrinter->ui->comboBox->currentText()).absolutePath()));
}

void FormPrinterPack::on_checkBox_4_toggled(bool checked)
{
    ui->spinBox_3->setEnabled(checked);
    formPrinter->workOrder->setInfor("multiple_rows_and_columns", checked?QString::number(ui->spinBox_3->value()):"");
}


void FormPrinterPack::on_spinBox_3_valueChanged(int arg1)
{
    formPrinter->workOrder->setInfor("multiple_rows_and_columns", QString::number(arg1));
}

